package com.dianping.cat.report;

import org.unidal.lookup.annotation.Named;

import java.util.concurrent.ConcurrentHashMap;

@Named
public class DomainValidator {

    private final ConcurrentHashMap<String, String> m_valids = new ConcurrentHashMap<>();

    public boolean validate(String domain) {
        if (!m_valids.containsKey(domain)) {
            int length = domain.length();
            char c;

            for (int i = 0; i < length; i++) {
                c = domain.charAt(i);

                if (c > 126 || c < 32) {
                    return false;
                }
            }
            m_valids.put(domain, domain);
        }
        return true;
    }
}
